#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200006;
const int INF = 1e9+9;
typedef long long ll;
ll x[MAXN];
int solve() {
  int n;cin>>n;
  for(int i=0;i<n;++i)cin>>x[i];
  ll sum=-INF, best=-INF;
  for(int i=0;i<n;++i) {
    sum = max(x[i],sum+x[i]);
    best = max(sum,best);
  }
  cout<<best<<"\n";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int tc; tc = 1;
  for(int t = 1; t <= tc; t++) {
    // cout << "Case #" << t << ": "
    solve();
  }
  return 0;
}
